// src/contexts/AppContext.jsx
import React, { createContext, useContext, useState } from 'react';

const AppContext = createContext();

export const AppProvider = ({ children }) => {
  const [selectedTrack, setSelectedTrack] = useState(null);
  const [selectedVehicle, setSelectedVehicle] = useState(null);
  const [calendar, setCalendar] = useState([]);
  const [challenges, setChallenges] = useState([]);
  const [forumPosts, setForumPosts] = useState([]);

  const value = {
    selectedTrack,
    setSelectedTrack,
    selectedVehicle,
    setSelectedVehicle,
    calendar,
    setCalendar,
    challenges,
    setChallenges,
    forumPosts,
    setForumPosts,
  };

  return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
};

export const useApp = () => {
  const context = useContext(AppContext);
  if (!context) {
    throw new Error('useApp must be used within an AppProvider');
  }
  return context;
};